.class final Lcom/baidu/crabsdk/a/e;
.super Ljava/lang/Object;

# interfaces
.implements Landroid/view/Choreographer$FrameCallback;


# annotations
.annotation build Landroid/annotation/TargetApi;
    value = 0x10
.end annotation


# static fields
.field static final an:Lcom/baidu/crabsdk/a/e;


# instance fields
.field private ao:Z

.field private ap:J

.field private aq:J

.field private ar:J

.field private as:I


# direct methods
.method static constructor <clinit>()V
    .locals 1

    new-instance v0, Lcom/baidu/crabsdk/a/e;

    invoke-direct {v0}, Lcom/baidu/crabsdk/a/e;-><init>()V

    sput-object v0, Lcom/baidu/crabsdk/a/e;->an:Lcom/baidu/crabsdk/a/e;

    return-void
.end method

.method private constructor <init>()V
    .locals 3

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/baidu/crabsdk/a/e;->ao:Z

    const-wide/16 v1, 0x0

    iput-wide v1, p0, Lcom/baidu/crabsdk/a/e;->ap:J

    const-wide/32 v1, 0x27bc86a

    iput-wide v1, p0, Lcom/baidu/crabsdk/a/e;->aq:J

    const-wide/32 v1, 0xfe5029

    iput-wide v1, p0, Lcom/baidu/crabsdk/a/e;->ar:J

    iput v0, p0, Lcom/baidu/crabsdk/a/e;->as:I

    return-void
.end method

.method static synthetic a(Lcom/baidu/crabsdk/a/e;)V
    .locals 7

    invoke-static {}, Lcom/baidu/crabsdk/a/a;->e()Lcom/baidu/crabsdk/a/a;

    move-result-object v0

    invoke-virtual {v0}, Lcom/baidu/crabsdk/a/a;->g()Ljava/util/Map;

    move-result-object v0

    if-nez v0, :cond_0

    const-string p0, "no keyStack; blockRecord = null; not a block!!!"

    invoke-static {p0}, Lcom/baidu/crabsdk/c/a;->v(Ljava/lang/String;)I

    return-void

    :cond_0
    new-instance v1, Ljava/lang/StringBuilder;

    const-string v2, "^^ -BlockCanaryCore- ^^"

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/lang/Object;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Lcom/baidu/crabsdk/c/a;->u(Ljava/lang/String;)I

    invoke-static {}, Lcom/baidu/crabsdk/a/c;->k()Landroid/content/Context;

    move-result-object v1

    const/4 v2, 0x1

    const/4 v3, 0x0

    invoke-static {v1, v3, v2}, Lcom/baidu/crabsdk/sender/e;->a(Landroid/content/Context;Ljava/lang/Throwable;Z)Ljava/util/Map;

    move-result-object v1

    invoke-interface {v1, v0}, Ljava/util/Map;->putAll(Ljava/util/Map;)V

    invoke-static {v1}, Lcom/baidu/crabsdk/sender/e;->a(Ljava/util/Map;)V

    invoke-static {v1}, Lcom/baidu/crabsdk/sender/g;->c(Ljava/util/Map;)Ljava/lang/String;

    move-result-object v0

    sget-object v1, Lcom/baidu/crabsdk/a;->d:Ljava/lang/String;

    invoke-static {}, Ljava/util/UUID;->randomUUID()Ljava/util/UUID;

    move-result-object v4

    invoke-virtual {v4}, Ljava/util/UUID;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-static {v1, v4}, Lcom/baidu/crabsdk/c/d;->c(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Lcom/baidu/crabsdk/c/d;->e(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    :try_start_0
    invoke-static {v1}, Lcom/baidu/crabsdk/c/e;->B(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    :catch_0
    move-exception v4

    invoke-virtual {v4}, Ljava/lang/Exception;->printStackTrace()V

    :goto_0
    invoke-static {}, Lcom/baidu/crabsdk/sender/f;->ac()V

    invoke-static {}, Lcom/baidu/crabsdk/sender/f;->U()Z

    move-result v4

    if-eqz v4, :cond_5

    const-string v4, "-BlockCanaryCore- switch on -  *^o^* doUploadBlock *^o^*"

    invoke-static {v4}, Lcom/baidu/crabsdk/c/a;->s(Ljava/lang/String;)I

    invoke-static {}, Lcom/baidu/crabsdk/sender/f;->Z()Z

    move-result v4

    if-eqz v4, :cond_4

    if-eqz v0, :cond_3

    :try_start_1
    invoke-virtual {v0}, Ljava/lang/String;->length()I

    move-result p0

    if-nez p0, :cond_1

    goto :goto_1

    :cond_1
    sget-boolean p0, Lcom/baidu/crabsdk/a;->H:Z
    :try_end_1
    .catch Ljava/io/UnsupportedEncodingException; {:try_start_1 .. :try_end_1} :catch_2
    .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_1

    const-string v3, "UTF-8"

    if-eqz p0, :cond_2

    :try_start_2
    new-instance p0, Ljava/io/ByteArrayOutputStream;

    invoke-direct {p0}, Ljava/io/ByteArrayOutputStream;-><init>()V

    new-instance v4, Ljava/util/zip/DeflaterOutputStream;

    new-instance v5, Ljava/util/zip/Deflater;

    const/16 v6, 0x9

    invoke-direct {v5, v6, v2}, Ljava/util/zip/Deflater;-><init>(IZ)V

    invoke-direct {v4, p0, v5}, Ljava/util/zip/DeflaterOutputStream;-><init>(Ljava/io/OutputStream;Ljava/util/zip/Deflater;)V

    invoke-virtual {v0, v3}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v0

    invoke-virtual {v4, v0}, Ljava/util/zip/DeflaterOutputStream;->write([B)V

    invoke-virtual {v4}, Ljava/util/zip/DeflaterOutputStream;->close()V

    invoke-virtual {p0}, Ljava/io/ByteArrayOutputStream;->toByteArray()[B

    move-result-object v3

    goto :goto_1

    :cond_2
    invoke-virtual {v0, v3}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v3

    goto :goto_1

    :catch_1
    move-exception p0

    goto :goto_2

    :catch_2
    move-exception p0

    goto :goto_3

    :cond_3
    :goto_1
    invoke-static {v3, v1}, Lcom/baidu/crabsdk/sender/i;->a([BLjava/lang/String;)V
    :try_end_2
    .catch Ljava/io/UnsupportedEncodingException; {:try_start_2 .. :try_end_2} :catch_2
    .catch Ljava/io/IOException; {:try_start_2 .. :try_end_2} :catch_1

    return-void

    :goto_2
    invoke-virtual {p0}, Ljava/io/IOException;->printStackTrace()V

    return-void

    :goto_3
    invoke-virtual {p0}, Ljava/io/UnsupportedEncodingException;->printStackTrace()V

    return-void

    :cond_4
    const-string v0, "CrashSwitch.canBlockUploadToday() == false"

    invoke-static {v0}, Lcom/baidu/crabsdk/c/a;->s(Ljava/lang/String;)I

    invoke-static {}, Lcom/baidu/crabsdk/a/b;->i()Lcom/baidu/crabsdk/a/b;

    move-result-object v0

    invoke-virtual {v0}, Lcom/baidu/crabsdk/a/b;->stop()V

    invoke-virtual {p0}, Lcom/baidu/crabsdk/a/e;->stop()V

    :cond_5
    return-void
.end method

.method private reset()V
    .locals 2

    const-wide/16 v0, 0x0

    iput-wide v0, p0, Lcom/baidu/crabsdk/a/e;->ap:J

    const/4 v0, 0x0

    iput v0, p0, Lcom/baidu/crabsdk/a/e;->as:I

    return-void
.end method


# virtual methods
.method public final doFrame(J)V
    .locals 7

    :try_start_0
    iget-wide v0, p0, Lcom/baidu/crabsdk/a/e;->ap:J

    const-wide/16 v2, 0x0

    cmp-long v4, v0, v2

    if-eqz v4, :cond_3

    iget-wide v0, p0, Lcom/baidu/crabsdk/a/e;->ap:J

    sub-long v0, p1, v0

    iget-wide v2, p0, Lcom/baidu/crabsdk/a/e;->aq:J

    cmp-long v4, v0, v2

    if-lez v4, :cond_0

    iget v2, p0, Lcom/baidu/crabsdk/a/e;->as:I

    int-to-long v2, v2

    iget-wide v4, p0, Lcom/baidu/crabsdk/a/e;->ar:J

    div-long/2addr v0, v4

    add-long/2addr v2, v0

    long-to-int v0, v2

    iput v0, p0, Lcom/baidu/crabsdk/a/e;->as:I

    goto :goto_0

    :cond_0
    iget v0, p0, Lcom/baidu/crabsdk/a/e;->as:I

    if-lez v0, :cond_3

    iget v0, p0, Lcom/baidu/crabsdk/a/e;->as:I

    const/16 v1, 0x1e

    const/4 v2, 0x1

    if-le v0, v1, :cond_2

    new-instance v0, Ljava/lang/StringBuilder;

    const-string v1, "^^ block skip frames = "

    invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    iget v1, p0, Lcom/baidu/crabsdk/a/e;->as:I

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    const-string v1, "\n^^ costs : "

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    sget-object v1, Ljava/util/concurrent/TimeUnit;->NANOSECONDS:Ljava/util/concurrent/TimeUnit;

    iget v3, p0, Lcom/baidu/crabsdk/a/e;->as:I

    int-to-long v3, v3

    iget-wide v5, p0, Lcom/baidu/crabsdk/a/e;->ar:J

    mul-long v3, v3, v5

    invoke-virtual {v1, v3, v4}, Ljava/util/concurrent/TimeUnit;->toMillis(J)J

    move-result-wide v3

    invoke-virtual {v0, v3, v4}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    const-string v1, "ms"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Lcom/baidu/crabsdk/c/a;->u(Ljava/lang/String;)I

    sget-object v0, Ljava/util/concurrent/TimeUnit;->NANOSECONDS:Ljava/util/concurrent/TimeUnit;

    iget v1, p0, Lcom/baidu/crabsdk/a/e;->as:I

    int-to-long v3, v1

    iget-wide v5, p0, Lcom/baidu/crabsdk/a/e;->ar:J

    mul-long v3, v3, v5

    invoke-virtual {v0, v3, v4}, Ljava/util/concurrent/TimeUnit;->toMillis(J)J

    move-result-wide v0

    sget v3, Lcom/baidu/crabsdk/a/a;->U:I

    int-to-long v3, v3

    cmp-long v5, v0, v3

    if-ltz v5, :cond_1

    invoke-static {}, Lcom/baidu/crabsdk/a/c;->j()Ljava/util/concurrent/ExecutorService;

    move-result-object v0

    new-instance v1, Lcom/baidu/crabsdk/a/f;

    invoke-direct {v1, p0}, Lcom/baidu/crabsdk/a/f;-><init>(Lcom/baidu/crabsdk/a/e;)V

    invoke-interface {v0, v1}, Ljava/util/concurrent/ExecutorService;->execute(Ljava/lang/Runnable;)V

    :cond_1
    iput v2, p0, Lcom/baidu/crabsdk/a/e;->as:I

    :cond_2
    iget v0, p0, Lcom/baidu/crabsdk/a/e;->as:I

    sub-int/2addr v0, v2

    iput v0, p0, Lcom/baidu/crabsdk/a/e;->as:I

    :cond_3
    :goto_0
    iput-wide p1, p0, Lcom/baidu/crabsdk/a/e;->ap:J
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    goto :goto_1

    :catchall_0
    move-exception p1

    new-instance p2, Ljava/lang/StringBuilder;

    const-string v0, "doFrame:"

    invoke-direct {p2, v0}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {p1}, Ljava/lang/Throwable;->toString()Ljava/lang/String;

    move-result-object p1

    invoke-virtual {p2, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {p2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p1

    invoke-static {p1}, Lcom/baidu/crabsdk/c/a;->v(Ljava/lang/String;)I

    :goto_1
    :try_start_1
    invoke-static {}, Landroid/view/Choreographer;->getInstance()Landroid/view/Choreographer;

    move-result-object p1

    sget-object p2, Lcom/baidu/crabsdk/a/e;->an:Lcom/baidu/crabsdk/a/e;

    invoke-virtual {p1, p2}, Landroid/view/Choreographer;->postFrameCallback(Landroid/view/Choreographer$FrameCallback;)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    return-void

    :catch_0
    move-exception p1

    invoke-virtual {p1}, Ljava/lang/Exception;->printStackTrace()V

    return-void
.end method

.method public final start()V
    .locals 2

    iget-boolean v0, p0, Lcom/baidu/crabsdk/a/e;->ao:Z

    if-eqz v0, :cond_0

    return-void

    :cond_0
    const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/baidu/crabsdk/a/e;->ao:Z

    invoke-direct {p0}, Lcom/baidu/crabsdk/a/e;->reset()V

    :try_start_0
    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v0

    invoke-static {}, Landroid/os/Looper;->myLooper()Landroid/os/Looper;

    move-result-object v1
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1

    if-ne v0, v1, :cond_1

    :try_start_1
    invoke-static {}, Landroid/view/Choreographer;->getInstance()Landroid/view/Choreographer;

    move-result-object v0

    sget-object v1, Lcom/baidu/crabsdk/a/e;->an:Lcom/baidu/crabsdk/a/e;

    invoke-virtual {v0, v1}, Landroid/view/Choreographer;->postFrameCallback(Landroid/view/Choreographer$FrameCallback;)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    return-void

    :catch_0
    move-exception v0

    :try_start_2
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    return-void

    :cond_1
    new-instance v0, Landroid/os/Handler;

    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v1

    invoke-direct {v0, v1}, Landroid/os/Handler;-><init>(Landroid/os/Looper;)V

    new-instance v1, Lcom/baidu/crabsdk/a/g;

    invoke-direct {v1, p0}, Lcom/baidu/crabsdk/a/g;-><init>(Lcom/baidu/crabsdk/a/e;)V

    invoke-virtual {v0, v1}, Landroid/os/Handler;->post(Ljava/lang/Runnable;)Z
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_1

    return-void

    :catch_1
    move-exception v0

    const-string v1, "postFrameCallback error!!"

    invoke-static {v1, v0}, Lcom/baidu/crabsdk/c/a;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    return-void
.end method

.method public final stop()V
    .locals 2

    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/baidu/crabsdk/a/e;->ao:Z

    invoke-direct {p0}, Lcom/baidu/crabsdk/a/e;->reset()V

    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v0

    invoke-static {}, Landroid/os/Looper;->myLooper()Landroid/os/Looper;

    move-result-object v1

    if-ne v0, v1, :cond_0

    :try_start_0
    invoke-static {}, Landroid/view/Choreographer;->getInstance()Landroid/view/Choreographer;

    move-result-object v0

    sget-object v1, Lcom/baidu/crabsdk/a/e;->an:Lcom/baidu/crabsdk/a/e;

    invoke-virtual {v0, v1}, Landroid/view/Choreographer;->removeFrameCallback(Landroid/view/Choreographer$FrameCallback;)V

    const-string v0, "stop FrameMonitor !!"

    invoke-static {v0}, Lcom/baidu/crabsdk/c/a;->s(Ljava/lang/String;)I
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    return-void

    :catch_0
    move-exception v0

    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    return-void

    :cond_0
    new-instance v0, Landroid/os/Handler;

    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v1

    invoke-direct {v0, v1}, Landroid/os/Handler;-><init>(Landroid/os/Looper;)V

    new-instance v1, Lcom/baidu/crabsdk/a/h;

    invoke-direct {v1, p0}, Lcom/baidu/crabsdk/a/h;-><init>(Lcom/baidu/crabsdk/a/e;)V

    invoke-virtual {v0, v1}, Landroid/os/Handler;->post(Ljava/lang/Runnable;)Z

    return-void
.end method
